package com.copa.l303;

/**
 * @author copa
 * @createDate 2022-09-06 11:45
 * @function 动态规划法
 */
public class Test2 {

    private int[] sums;

    public Test2(int[] nums) {
        this.sums = new int[nums.length + 1];
        for (int i = 0; i < nums.length; i++) {
            sums[i + 1] = sums[i] + nums[i];
        }
    }

    public int sumRange(int left, int right) {
       return sums[right + 1] - sums[left];
    }

    /**
     * Your NumArray object will be instantiated and called as such:
     * NumArray obj = new NumArray(nums);
     * int param_1 = obj.sumRange(left,right);
     */
    public static void main(String[] args) {
        int[] nums = {-2, 0, 3, -5, 2, -1};
        Test2 test1 = new Test2(nums);
        System.out.println(test1.sumRange(0, 2));
        System.out.println(test1.sumRange(2, 5));
        System.out.println(test1.sumRange(0, 5));

    }
}

